<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="financing/accepts/edits">

    <div class="form-group">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2">{:__('第三方服务费')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-other_cost" readonly="readonly" class="form-control" name="row[other_cost]" type="text" value="{$row.other_cost|htmlentities}">
        </div>
    </div>

    <div class="form-group">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2">{:__('原始金额')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-count_cost" readonly="readonly" class="form-control" name="row[count_cost]" type="text" value="{$row.count_cost|htmlentities}">
        </div>
    </div>

    <div class="form-group">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2">{:__('会员抵扣服务金额')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-vip_deduction" readonly="readonly" class="form-control" name="row[vip_deduction]" type="text" value="{$row.vip_deduction|htmlentities}">
        </div>
    </div>

    <div class="form-group">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2">{:__('会员优惠金额')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-vip_discounts" readonly="readonly" class="form-control" name="row[vip_discounts]" type="text" value="{$row.vip_discounts|htmlentities}">
        </div>
    </div>

    <div class="form-group">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2">{:__('申请优惠金额')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-iscounts_cost" readonly="readonly" class="form-control" name="row[iscounts_cost]" type="text" value="{$row.iscounts_cost|htmlentities}">
        </div>
    </div>

    <div class="form-group" id="custom">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2">{$row.custom_name|htmlentities}</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-new_price" readonly="readonly" class="form-control" name="row[new_price]" type="text" value="{$row.custom_price|htmlentities}">
        </div>
        <input type="hidden" name="row[custom_name]" value="{$row.custom_name|htmlentities}">
    </div>


    <div class="form-group">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2">{:__('应收金额')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-receivable" readonly="readonly" class="form-control" name="row[receivable]" type="text" value="{$row.receivable|htmlentities}">
        </div>
    </div>

    <div class="form-group">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2">{:__('赊账金额')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-on_account" readonly="readonly" class="form-control" name="row[on_account]" type="text" value="0">
        </div>
    </div>


<!--    <div class="form-group" id="is_signatures">-->
<!--        <label for="is_signature" class="control-label col-xs-12 col-sm-2">{:__('选择是否签字确认')}:</label>-->
<!--        <div class="col-xs-12 col-sm-8">-->
<!--            <select id="is_signature"  name="row[is_signatures]" class="form-control selectpicker">-->
<!--                <option data-type="type" value="1" {if condition="$row.is_signature==1"}selected{/if}>是</option>-->
<!--                <option data-type="type" value="0" {if condition="$row.is_signature==0"}selected{/if}>否</option>-->
<!--            </select>-->

<!--        </div>-->
<!--    </div>-->


    <div class="form-group" id="reality_cost">
        <label for="c-count_cost" class="control-label col-xs-12 col-sm-2"><span style="color: red;font-size: 15px">*</span>{:__('实收金额')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-reality_cost" class="form-control" name="row[reality_cost]" type="text" value="0">
            <span style="color:red">提醒：当实收金额小于应收金额会生成赊账欠款单</span>
        </div>
    </div>

    <div class="form-group" id="pays">
    <label class="control-label col-xs-12 col-sm-2">{:__('支付方式')}:</label>
    <div id="pay" class="col-xs-12 col-sm-8">
    {:build_radios('row[pay]', ['1'=>__('转账'), '2'=>__('现金'),'3'=>__('pos机'),'4'=>__('支付宝'),'5'=>__('微信'),'6'=>__('储值卡'),'7'=>__('积分')])}
    </div>
    </div>

    <input type="hidden" name="row[id]" value="{$row.id|htmlentities}">
    <!--<input type="hidden" name="row[pay]" value="{$row.pay|htmlentities}">-->
    <input type="hidden" name="row[vip_id]" value="{$row.vip_id|htmlentities}">
    <input type="hidden" name="row[check_code]" value="{$row.check_code|htmlentities}">
    <input type="hidden" name="row[type]" value="{$row.type|htmlentities}">
    <input type="hidden" name="row[is_types]" value="{$row.is_types|htmlentities}">
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>

</form>

<script src="/assets/img/jquery-3.4.1.min.js"></script>
<script>
    var is_custom = {$row.is_custom};
    var is_signature = {$row.is_signature};
    if(is_custom == 1){
        $('#custom').show();
    }else {
        $('#custom').hide();
    }

    //console.log(is_custom);

    if(is_signature == 1){
        $('#reality_cost').show();
        $('#pays').show();
    }else {
        $('#reality_cost').hide();
        $('#pays').hide();
    }

    $('#is_signatures').hide();

    $('#c-reality_cost').keyup(function() {
        var receivable = $("#c-receivable").val();
        var reality_cost = $("#c-reality_cost").val();

        //判断当前数量参数是否为数值，如果不是数值则终止计算。
        if (!$.isNumeric($(this).val())) {
            return false;
        }

        //let on_account = receivable-reality_cost;
        let on_account = numSub(receivable,reality_cost);
        //console.log(on_account);
        if (on_account < 0){
           var on_accounts = 0;
        }else {
            var on_accounts = on_account;
        }

        $("#c-on_account").val(on_accounts);

    });


    function numSub(num1, num2) {
        var baseNum, baseNum1, baseNum2;
        var precision;// 精度
        try {
            baseNum1 = num1.toString().split(".")[1].length;
        } catch (e) {
            baseNum1 = 0;
        }
        try {
            baseNum2 = num2.toString().split(".")[1].length;
        } catch (e) {
            baseNum2 = 0;
        }
        baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
        precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;
        return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision);
    };

</script>

